/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.jdbc.driver;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import org.apache.commons.dbcp2.*;

/**
 *
 * @author 虎
 */
public class JdbcUtil {

    private final static String DRIVERNAME = "com.mysql.jdbc.Driver";
    private final static String URL = "jdbc:mysql://localhost:3306/vipusers?useSSL=false&&rewriteBatchedStatements=true";
    private final static String USER = "root";
    private final static String PWD = "123456";
    private static BasicDataSource ds = null;

//    static {
//        ds = new BasicDataSource();
//        ds.setDriverClassName(DRIVERNAME);
//        ds.setTestOnBorrow(true);
//        ds.setUsername(USER);
//        ds.setPassword(PWD);
//        ds.setUrl(URL);
//    }
//
//    public static Connection getConn() {
//        try {
//            return ds.getConnection();
//        } catch (Exception e) {
//            e.printStackTrace();
//        }
//        return null;
//    }

    
    
    
     static{ try{ Class.forName(DRIVERNAME); }catch(ClassNotFoundException e){
     } }
    
     public static Connection getConn(){ try{ return
      DriverManager.getConnection(URL, USER, PWD); }catch(SQLException e){ }
      return null;}
     
    public static void close(Connection conn, Statement st, ResultSet res) {
        if (st != null) {
            try {
                st.close();
            } catch (SQLException e) {
            }
        }
        if (conn != null) {
            try {
                conn.close();
            } catch (SQLException e) {
            }
        }
        if (res != null) {
            try {
                res.close();
            } catch (SQLException e) {
            }
        }
    }
}
